package com.rd.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rd.pojo.Dept;
import com.rd.service.IDeptService;
import com.rd.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lsl
 * @since 2024-06-06
 */
@RestController
@RequestMapping("/dept")
public class DeptController {
    @Autowired
    private IDeptService deptService;

    @GetMapping("/list")
    public R list(@RequestParam("page") int page,
                  @RequestParam("limit") int limit) {
        System.out.println("页码:" + page + ",每页显示记录个数:" + limit);
        //创建一个分页插件工具对象，并传入页码和每页显示记录个数
        Page<Dept> tool = new Page<Dept>(page, limit);
        //调用mybatis-plus提供的IService接口中提供page方法
        Page<Dept> deptPage = deptService.page(tool);
        //此时已经分页查询成功，只需要从adminPage中获取信息
        long total = deptPage.getTotal(); //获取总条数
        List<Dept> list = deptPage.getRecords();//获取页面是显示的数据
        //将list集合和count的值传递给前端table组件页面上显示
        return R.ok().setData(list).setCount(total);
    }
}
